<!DOCTYPE html>
<html class="ui-page-login">

<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no" />
	<title>loginweixin-微信登录</title>
	<link href="css/mui.min.css" rel="stylesheet" />
	<!--
        <link href="css/styleloginwx.css" rel="stylesheet" />
        -->
	<style>
		div#mid {
			position: fixed;
			margin: 0;
			padding: 0;
			width: 85%;
			left: 1rem;
			bottom: .5rem;
			font-size: 20px;
		}

		img#userphoto {
			border-radius: 128px;
			border: none;
			width: 128px;
			margin-top: 2rem;
			margin-left: 4rem;
		}

		img.im {
			width: 80%;
			height: 3rem;
			margin-bottom: 3rem;
			margin-left: 1em;
		}

		div#div1 {
			position: fixed;
			top: 0;
			left: 0;
			bottom: 0;
			right: 0;
			z-index: -1;
		}

		div#div1>img {
			height: 100%;
			width: 100%;
			border: 0;
		}
	</style>
</head>

<body>
	<div id="mid">
		<ul>
			<img alt="" id="userphoto" src="">
		</ul>
		<ul class="mui-input-row mui-radio">
			<input type="checkbox" id="icbx" checked="checked" />
			<a style="color: #212121;margin-left: 1.5rem;">获得你的公开信息</a>
		</ul>
		<ul>
			<img alt="" class="im" id="wxLogin" src="">
		</ul>
	</div>

	<div id="div1">
		<img src="">
	</div>

	<script src="js/mui.min.js"></script>
	<script src="js/mui.enterfocus.js"></script>
	<script src="js/common.js"></script>
	<script src="js/app.js"></script>
	<script>
		mui.init({
			statusBarBackground: '#f7f7f7'
		});
		mui.plusReady(function () {
			var guidePage = plus.webview.getWebviewById(plus.runtime.appid);
			if (guidePage) {
				plus.webview.close(guidePage);
			}

			plus.screen.lockOrientation("portrait-primary");
			var userphoto = document.getElementById('userphoto');
			userphoto.src = plus.storage.getItem("headimgurl");

			var system = {};
			var p = navigator.platform;
			var icbx = document.getElementById('icbx');
			var wxLogin = document.getElementById('wxLogin');

			system.Linux7 = p.indexOf("Linux armv7l") == 0;
			if (system.Linux7) {
				//plus.nativeUI.toast(p);
				wxLogin.style.marginTop = '7rem';
				icbx.style.marginTop = '2rem';
			} else {
				system.Linux = p.indexOf("Linux") == 0;
				if (system.Linux) {
					wxLogin.style.marginTop = '7rem';
					icbx.style.marginTop = '2rem';
				}
				system.iPhone = p.indexOf("iPhone") == 0;
				if (system.iPhone) {
					wxLogin.style.marginTop = '4rem';
					icbx.style.marginTop = '.3rem';
				}
				//system.Win = p.indexOf("Win") == 0;
			}

			app.setState(null);
			var settings = app.getSettings();
			var state = app.getState();
			var mainPage = plus.webview.getWebviewById("main");
			var main_loaded_flag = false;
			if (!mainPage) {
				mainPage = mui.preload({
					"id": 'main',
					"url": 'main.html'
				});
			} else {
				main_loaded_flag = true;
			}

			mainPage.addEventListener("loaded", function () {
				main_loaded_flag = true;
			});
			var toMain = function () {
				//使用定时器的原因：
				//可能执行太快，main页面loaded事件尚未触发就执行自定义事件，此时必然会失败
				var id = setInterval(function () {
					if (main_loaded_flag) {
						clearInterval(id);
						mui.fire(mainPage, 'show', null);
						mainPage.show("pop-in");
					}
				}, 20);
			};

			//检查 "登录状态/锁屏状态" 开始
			if (settings.autoLogin && state.token && settings.gestures) {
				/* mui.openWindow({
					url: 'unlock.html',
					id: 'unlock',
					show: {
						aniShow: 'pop-in'
					},
					waiting: {
						autoShow: false
					}
				}); */
			} else if (settings.autoLogin && state.token) {
				toMain();
			} else {
				var p = window.screen.availHeight / window.screen.availWidth;
				var styleElement = document.getElementById('mid');
				styleElement.style.marginTop = (p * 39) + "%";

				document.getElementById('wxLogin').addEventListener('tap', function () {
					var loginPage = plus.webview.getWebviewById('login');
					if (loginPage) {
						plus.webview.close(loginPage);
					}
					mui.openWindow({
						id: 'main',
						url: 'main.html',
						show: {
							aniShow: 'none'
						},
						waiting: {
							autoShow: true
						}
					});
					plus.webview.close(plus.webview.currentWebview());
				});
			}
		});

		/* function submit() {
			clicked("main.html", true, {
				"mid": "通过extras传递数据"
			});
		} */
	</script>
</body>

</html>